package com.wsq.annotation.demo;

import android.util.Log;

import com.wsq.annotation.annotation.AnnotationClass;
import com.wsq.annotation.annotation.MyAnnotationRuntime;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * Date:2022/7/11
 * Time:21:51
 * author:wushengqi
 */
public class HandleAnnotation {
    public Method handleMethodAnnotation(AnnotationDemo annotationDemo) throws NoSuchMethodException {
        Method method = annotationDemo.getClass().getMethod("methodAnnotation", new Class[]{});
        Annotation[] annotations = method.getAnnotations();

        for (Annotation annotation: annotations){
            if (annotation instanceof MyAnnotationRuntime){
                Log.e("HandleAnnotation", "注解接口：MyAnnotationRuntime  " + "注入值：" + ((MyAnnotationRuntime) annotation).value());
            }else{
                Log.e("HandleAnnotation", annotation.getClass().getName());
            }
        }

        return method;
    }

    public void handleClassAnnotation(AnnotationDemo annotationDemo) throws NoSuchMethodException {
//        Method method = annotationDemo.getClass().getMethod("methodAnnotation", new Class[]{});
        Annotation[] annotations = annotationDemo.getClass().getAnnotations();

        for (Annotation annotation: annotations){
            if (annotation instanceof AnnotationClass){
                Log.e("HandleAnnotation", "注解接口：AnnotationClass  " + "注入值：" + ((AnnotationClass) annotation).value());
            }else{
                Log.e("HandleAnnotation", annotation.getClass().getName());
            }
        }

    }
}
